****************************************************************************************************************************************************
***Analysis of Experiment 2 in Pedersen, Rasmus T: "Attitudes on the Size of Unemployment Benefits"*************************************************
****************************************************************************************************************************************************
***Written for Stata 15*****************************************************************************************************************************
****************************************************************************************************************************************************

**********************************
***Installing required packages***
**********************************

*Install these packages, if the are not already installed:
* ssc install estout //Run this line if estout is not already installed (used when creating regression tables)
* net install grc1leg.pkg //Run this line if grc1leg is not already installed (used when combining graphs)
* ssc install coefplot //Run this line if "Coefplot" is not already installed (used when plotting results in graphs)
* ssc install blindschemes //Run this line if "blindschemes is not already installed (used to control graph layout) 

*******************************
***Setting the figure scheme***
*******************************
set scheme plotplainblind


***************************************************************************************************************************************************
***Getting the data********************************************************************************************************************************
***************************************************************************************************************************************************
clear all
set more off

	cd  "C:\Attitudes_on_Benefits"
	use "C:\Attitudes_on_Benefits\Benefits_study2.dta" 

**********************************************************************************************************************************************************
***Recoding, Creating variables and Attaching Value Labels************************************************************************************************
**********************************************************************************************************************************************************

***Recoding Covariates***

*Left-Right Position*
recode q1  (977=.), gen(LR_unstd)
replace LR_unstd=LR_unstd-1
gen LR=LR_unstd/10


	by FT15, sort: egen FT15_median = median(LR)
	by FT_next, sort: egen FT_next_median = median(LR)
	alpha LR FT15_median FT_next_median, item gen(LR_total) 
	gen LR_total_unstd=round(LR_total*10)
	sum LR_total
	gen LR_total_sd1=LR_total/r(sd)
	
	gen LR_impute=LR_unstd
	replace LR_impute=LR_total_unstd if LR==.
	recode LR_impute (0 1 2 3=0 "Left") (4 5 6=1 "Center") (7 8 9 10=2 "Right"), gen(LCR)
	
*Gender*
recode gender (1=1 "female") (2=0 "male"), gen(female)	 

*Education - completetion of tertiary education is set to "some college"*
recode profile_education (1 2 3 5 9=0) (4 6 7 8=1), gen(Somecollege)	


***Recoding the IV***
gen condition=.
replace condition=1 if q2a!=. 
replace condition=2 if q2b!=. 
replace condition=3 if q2c!=. 
label define condition 	1 "DKK 6.923" ///	
						2 "DKK 7.000" ///
						3 "DKK 7.078"
label values condition condition
recode condition (1 3=1) (2=0), gen(precise_condition)

***Recoding the DV***

*Accept of suggested value*
gen accept_value=.
replace accept_value=q2a if q2a!=. 
replace accept_value=q2b if q2b!=. 
replace accept_value=q2c if q2c!=. 
label values accept_value q4
tab accept_value
recode accept_value (2 3=0), gen(accept_value_yes)

*Preferred value*
gen preferred_week=.
replace preferred_week=q3a if q3a!=.
replace preferred_week=q3b if q3b!=.
replace preferred_week=q3c if q3c!=. 
replace preferred_week=6923 if q2a==1
replace preferred_week=7000 if q2b==1
replace preferred_week=7078 if q2c==1

gen preferred_month=preferred_week*(52/12)


*dealing with outliers*
sum preferred_week, detail
tab condition, nol
gen preferred_week_trim5=preferred_week
foreach x in 1 2 3 {
sum preferred_week_trim5 if condition==`x', d 
replace preferred_week_trim5=. if condition==`x' & preferred_week_trim5 > r(p95)
replace preferred_week_trim5=. if condition==`x' & preferred_week_trim5 < r(p5)
}

*

***adjustment from anchor***
gen adjustment_trim5=.
replace adjustment_trim5=0-(6923-preferred_week_trim5) if condition==1
replace adjustment_trim5=0-(7000-preferred_week_trim5) if condition==2
replace adjustment_trim5=0-(7078-preferred_week_trim5) if condition==3


**conflicting answers**
gen conflict_answer=0
recode conflict_answer (0=1) if condition==1 & accept_value==2 & preferred_week>6923
recode conflict_answer (0=1) if condition==1 & accept_value==3 & preferred_week<6923
recode conflict_answer (0=1) if condition==2 & accept_value==2 & preferred_week>7000
recode conflict_answer (0=1) if condition==2 & accept_value==3 & preferred_week<7000
recode conflict_answer (0=1) if condition==3 & accept_value==2 & preferred_week>7078
recode conflict_answer (0=1) if condition==3 & accept_value==3 & preferred_week<7078

*Response latencies*
gen time_on_anchor=max(page_q2_timing, page_q3_timing, page_q4_timing)
gen time_on_number=max(page_q5_timing, page_q6_timing, page_q7_timing)
gen time_on_anchor_log=log(time_on_anchor)
gen time_on_number_log=log(time_on_number)
egen time_on_anchor_rank=rank(time_on_anchor)
egen time_on_number_rank=rank(time_on_number)



*Perception of party
recode q4_1 (977=.), gen(thorough)
recode q4_2 (977=.), gen(notserious)
recode q4_3 (977=.), gen(unrealistic)
recode q4_4 (977=.), gen(worry)
recode q4_5 (977=.), gen(squander)
recode q4_6 (977=.), gen(gettingvotes)

factor thorough notserious unrealistic worry squander gettingvotes
alpha thorough notserious unrealistic worry squander gettingvotes, min(1) item reverse(notserious unrealistic squander gettingvotes) gen(perception_uns) 
//alpha does not increase, when "min" is increased
gen perception=(perception_uns+5)/10

*Completion*
gen completed=0
recode completed (0=1) if q4_6!=.


*Response latencies*

	*version 1 - using logged values
	 gen accept_timing_log=ln(max(page_q2_timing, page_q3_timing, page_q4_timing ))
	 gen preferred_timing_log=ln(max(page_q5_timing, page_q6_timing, page_q7_timing ))
	 
	*version 2 - using trimmed values
	gen accept_timing_trim5=(max(page_q2_timing, page_q3_timing, page_q4_timing ))
	foreach x in 1 2 3 {
	sum accept_timing_trim5 if condition==`x', d 
	replace accept_timing_trim5=. if condition==`x' & accept_timing_trim5 > r(p95)
	replace accept_timing_trim5=. if condition==`x' & accept_timing_trim5 < r(p5)
	}

	*
	 recode accept_timing_trim5 (0=.)
		
	gen preferred_timing_trim5=(max(page_q5_timing, page_q6_timing, page_q7_timing ))
	foreach x in 1 2 3 {
	sum preferred_timing_trim5 if condition==`x', d 
	replace preferred_timing_trim5=. if condition==`x' & preferred_timing_trim5 > r(p95)
	replace preferred_timing_trim5=. if condition==`x' & preferred_timing_trim5 < r(p5)
	}

	*
	 recode preferred_timing_trim5 (0=.)

	 *version 2 - using ranks
	 egen accept_timing_rank=rank(max(page_q2_timing, page_q3_timing, page_q4_timing )) if (max(page_q2_timing, page_q3_timing, page_q4_timing )>0)
	 egen preferred_timing_rank=rank(max(page_q5_timing, page_q6_timing, page_q7_timing )) if (max(page_q5_timing, page_q6_timing, page_q7_timing )>0)	 
	 
	 
************************************************************************************************************************************************************
***Analyses*************************************************************************************************************************************************
************************************************************************************************************************************************************
**completition**
	**completition**
	tab completed, missing // 2,152 started the survey, and 2036 respondents answered all questions for this experiment, 
	di (2152-2036)/2152 // drop-off is 5,4 percent
	tab completed condition if q1!=., exact chi // drop off did not differ significantly among conditions
	**demographics**
	tab female if completed!=0
	sum age if completed!=0
	tab Somecollege if completed!=0
	sum LR_impute if completed!=0

***Do left and right disagree on the proper sixe of benefits?***
reg preferred_week_trim5  i.LR_impute
	margins, at(LR_impute=(0(1)10)) 
	marginsplot //just like in experiment 1, there is an approcimately linear relations between LR and preferred size of benefits

	*ROBUSTNESS: Alternative LR-scale yields essentially same result
	reg preferred_week_trim5  i.LR_total_unstd
	margins, at(LR_total_unstd=(1(1)8)) 
	marginsplot 
	
	reg preferred_week_trim5  LR
	reg preferred_week_trim5  i.LR_unstd
	margins, at(LR_unstd=(0(1)10)) 
	marginsplot //nogenlunde lineært


***Does precision affect stated preferences? 
	reg preferred_week_trim5 ib2.condition, robust //yes, it does
	margins, at(condition=(1 2 3)) pwcompare(effects) //all groups differ significantly from each other
	margins, at(condition=(1 2 3)) post
	eststo effect_main
	coefplot(effect_main) ///
			, vert legend(rows(1) position(12) size(large)) msymbol(circle) msize(large)	///
			title(" ") ytitle("Preferred size of benefits (DKK/week)", size(medium)) xtitle("") 				///
			coeflabels(	1._at=`" "Condition 1:" "6,923/week" "(Precise)   " "'  ///
						2._at=`" "Condition 2:  " "7,000/week" "(Rounded)     " "'  ///
						3._at= `" "Condition 3:" "7,078/week" "(Precise)    " "' ) ///
						legend(off) 	msize(medlarge)  ylabel(5000(500)7000) ///
						xlabel(, labsize(medsmall) labcolor(black)) ylabel(, labsize(medium) labcolor(black)) level(95) ///
						note(" " "Note: Values are trimmed means with 95% C.I. (n=1,913).", size(medium)) title("") ///
						ysize(3) xsize(6)
						graph save ex2_all_conditions, replace
						graph export ex2_all_conditions.tif, replace //This is figure 4 in the paper
	
	
	di 358.2335/ -138.7282 //the difference between condition 2 and 3 corresponds to difference of 2.6 points on LR scale
	
	*collapsing the two precise treatments*
	esize twosample preferred_week_trim5  , by(precise_condition) cohensd hedgesg


***Regression used for analyses of LR_interactions	
			reg preferred_week_trim5  i.LCR##ib2.condition, robust
			eststo pref_week_int_c3
			margins, at(condition=(1 2 3) LCR=(0)) pwcompare(effects)
			margins, at(condition=(1 2 3) LCR=(0)) post
			eststo LR_int1
			estimates restore pref_week_int_c3
			margins, at(condition=(1 2 3) LCR=(1)) pwcompare(effects)
			margins, at(condition=(1 2 3) LCR=(1)) post
			eststo LR_int2
			estimates restore pref_week_int_c3
			margins, at(condition=(1 2 3) LCR=(2)) pwcompare(effects)
			margins, at(condition=(1 2 3) LCR=(2)) post
			eststo LR_int3
			coefplot 	(LR_int1, label("Left") msymbol(circle) msize(large) mfcolor(gs15) mlcolor(black) ciopts(lcolor(black)) offset(-.1)) ///
						(LR_int2,label("Center")msymbol(circle) msize(large) mfcolor(gs10) mlcolor(black) ciopts(lcolor(black)) offset(0))  ///
						(LR_int3, label("Right")msymbol(circle) msize(large) mfcolor(gs5) mlcolor(black) ciopts(lcolor(black)) offset(.1)) ///
						, vert legend(rows(1) subtitle("Position on Left-Right Scale:", position(9)) position(12) region(lcolor(gs10) lwidth(vthin)) size(medium)) 	///
						title(" ") ytitle("Preferred size of benefits (DKK/week)", size(medium)) xtitle("") 	///
						coeflabels(	1._at=`" "Condition 1:" "6,923/week" "(Precise)   " "'  ///
									2._at=`" "Condition 2:  " "7,000/week" "(Rounded)     " "'  ///
									3._at= `" "Condition 3:" "7,078/week" "(Precise)    " "' ) 	///
						msize(medium) ylabel(5000(500)7000) ///
						xlabel(, labsize(medsmall) labcolor(black)) ylabel(, labsize(medium) labcolor(black)) level(95) ///
						note(" " "Note: Values are trimmed means with 95% C.I. (n=1,931).", size(medium)) ///
						ysize(3) xsize(6)
						graph save ex2_LR_all_conditions, replace
						graph export ex2_LR_all_conditions.tif, replace //This is Figure 5 in the paper
						
						
			*Collapsing the two precise treatments*
			esize twosample preferred_week_trim5  , by(precise_condition) cohensd hedgesg
			reg preferred_week_trim5  i.LCR##i.precise_condition
			margins, at(precise_condition=(0 1) LCR=(0)) pwcompare(effects)
			margins, at(precise_condition=(0 1) LCR=(1)) pwcompare(effects)
			margins, at(precise_condition=(0 1) LCR=(2)) pwcompare(effects)
			margins, dydx(precise_condition) at(LCR=(0 1 2))	
			
***Are differences attributable to difference in accept of anchor***
	tab accept_value_yes condition if preferred_week_trim5!=., col chi freq //Large share of respondents accept anchor, but large differences between conditions
	logit accept_value_yes i.condition if preferred_week_trim5!=.
	margins, over(condition) cformat(%9.2f)
	margins, over(condition) pwcompare(effects) 	
	
	***Does precision affect acceptance of anchor***	
	tab condition accept_value if preferred_week_trim5!=. , chi  row
	tab precise_condition accept_value if preferred_week_trim5!=., chi  row
	tab precise_condition accept_value_yes if preferred_week_trim5!=., chi row

	***Does precision affect subsequent adjustment, if anchor not accepted***
	reg preferred_week_trim5 ib2.condition if accept_value!=1
	margins, over(condition) pwcompare(effects) 
	margins, over(condition)
	margins, dydx(condition)

	reg adjustment_trim5 ib2.condition if accept_value!=1
	margins, over(condition) pwcompare(effects) 
	margins, over(condition)
	margins, dydx(condition)
	marginsplot, recast(bar) xlabel(, labsize(small) angle(forty_five)) horizontal xlabel(0(1000)800) xtitle("")


***Does precision affect party perceptions***
	reg perception ib2.condition if preferred_week_trim5!=. //No ,not at all
	margins, at(condition=(1 2 3)) pwcompare(effects) //no differences
	margins, at(condition=(1 2 3))
	marginsplot, recast(scatter) recastci(rspike) xlabel(, labsize(small) angle(forty_five)) ylabel(0(.1).5, gmin grid gstyle(minor)) xtitle("") ///
				title("") ytitle("", size(medsmall) margin(right)) xscale(range(0.5 3.5)) ///
				xlabel(1 `" "Condition 1:" "6,923/week" "(Precise)   " "' 2 `" "Condition 2:  " "7,000/week" "(Rounded)     " "' 3 `" "Condition 3:" "7,078/Week" "(Precise)    " "' ,labsize(small) ) ///
				scheme(s1mono) plotregion(lcolor(none)) ///
				note(" " "Note: Values are means with 95% C.I.")
	graph save perceptions, replace
	graph export perceptions.emf, replace
	
	reg thorough i.condition //Nothing!
	reg notserious i.condition //Nothing!
	reg unrealistic i.condition //Nothing!
	reg worry i.condition //Nothing!
	reg squander i.condition //Nothing!
	reg gettingvotes i.condition //Nothing!
	
	
	reg perception ib2.condition##i.LCR if preferred_week_trim5!=. //No ,not at all
	margins, at(condition=(1 2 3) LCR=0) pwcompare(effects) //no differences
	margins, at(condition=(1 2 3) LCR=1) pwcompare(effects) //no differences
	margins, at(condition=(1 2 3) LCR=2) pwcompare(effects) //no differences


**********************************************************************************************************************************************************
***Robustness*********************************************************************************************************************************************
**********************************************************************************************************************************************************

//What happens if we exclude respondents with conflicting answers?
reg preferred_week_trim5 ib2.condition if conflict_answer!=1, robust //
	margins, over(condition) pwcompare(effects) //all groups differ significantly from each other
	margins, over(condition)


//What happens if we exclude respondents adjusting upwards
	reg preferred_week_trim5 ib2.condition if adjustment<1, robust //
	margins, over(condition) pwcompare(effects) //difference between conditions 1 and 2 become smaller and only marginally significant (p=.12) - But still in right direction
	margins, over(condition)

	
//what happens if we use median instead of trimmed means?
	*LR-relationsship*
	qreg preferred_week  i.LR_total_unstd
	margins, at(LR_total_unstd=(1(1)8)) 
	marginsplot, title("", size(medium)) subtitle(, size(small)box fcolor(none)) ///
			recast(scatter) recastci(rspike) ytitle("Preferred size of benefits (DKK/Week)", size(small) margin(0 1 0 0))  xtitle("Left-Right position") ///
			scheme(s1mono) plotregion(lcolor(none)) ///
			note(" " "Note: Values are based on quantile regression with 95% C.I. (n=2,094)") 
	
		
	*Experimental treatment effects*
	qreg preferred_week ib2.condition //still significant effects of format
	margins, over(condition) pwcompare(effects) //the two precise conditions do not differ from each other (but differ from rounded, so conclusions hold)
	margins, over(condition)
	marginsplot, recast(bar) xlabel(, labsize(small) angle(forty_five)) horizontal xlabel(0(1000)8000) xtitle("")

//what happens if we use robust regression instead of trimmed means?	
	
	*LR-relationsship*
	qreg preferred_week  i.LR_total_unstd
	margins, at(LR_total_unstd=(1(1)8)) 
	marginsplot, title("", size(medium)) subtitle(, size(small)box fcolor(none)) ///
			recast(scatter) recastci(rspike) ytitle("Preferred size of benefits (DKK/Week)", size(small) margin(0 1 0 0))  xtitle("Left-Right position") ///
			scheme(s1mono) plotregion(lcolor(none)) ///
			note(" " "Note: Values are based on robust regression with 95% C.I. (n=2,094)") 
	
	*Experimental treatment effects*	
		rreg preferred_week i.condition //
		margins, over(condition) pwcompare(effects) //unlike analysis with trimmed means, difference between condtion 4 and 5 is insignificant. All other results substantively similar
		margins, over(condition)
		marginsplot, recast(scatter) xlabel(, labsize(small) angle(forty_five)) horizontal xlabel(3000(1000)7000) xtitle("")


erase ex2_all_conditions.gph
erase ex2_LR_all_conditions.gph
erase perceptions.gph
erase perceptions.emf

		
		
*************************
***THE END***************
*************************



